﻿package mortal.game.view.ActionIconPublic.wechatReward
{
    import __AS3__.vec.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.events.*;
    import flash.text.*;
    import mortal.common.global.*;
    import mortal.component.window.*;
    import mortal.game.manager.*;
    import mortal.game.manager.msgTip.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.firstReCharge.*;
    import mortal.game.view.rebate.data.*;
    import mortal.mvc.interfaces.*;

    public class WechatRewardModule extends BaseWindow
    {
        private var _textInput:GTextInput;
        private var _getRewardBtn:GLoadingButton;
        private var _rewardList:Vector.<EffectItem>;
        private static var _instance:WechatRewardModule;

        public function WechatRewardModule(param1:ILayer = null)
        {
            this._rewardList = new Vector.<EffectItem>;
            this.setSize(824, 572);
            super(param1);
            this.title = Language.getString(35101);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.wechatGiftBg, 8, 33, this));
            var _loc_1:* = Language.getString(35102);
            this.pushUIToDisposeVec(UIFactory.gTextField(_loc_1, 575, 170, 240, 40, this, null, true));
            _loc_1 = Language.getString(35103);
            this.pushUIToDisposeVec(UIFactory.gTextField(_loc_1, 575, 225, 240, 40, this, null, true));
            _loc_1 = Language.getString(35104);
            this.pushUIToDisposeVec(UIFactory.gTextField(_loc_1, 575, 280, 240, 40, this, null, true));
            var _loc_2:* = GlobalStyle.textFormatBai;
            _loc_2.size = 16;
            var _loc_3:* = GlobalStyle.textFormatHui;
            _loc_3.size = 16;
            this._textInput = UIFactory.gTextInput(270, 370, 350, 33, this);
            this._textInput.setStyle("textFormat", _loc_2);
            this._textInput.defaultTextTextFormat = _loc_3;
            this._textInput.maxChars = 42;
            this._textInput.defaultText = Language.getString(35105);
            this._getRewardBtn = UIFactory.gLoadingButton(ResFileConst.TakeRewardBtn, 360, 520, 130, 44, this);
            this._getRewardBtn.configEventListener(MouseEvent.CLICK, this.getReward);
            this.updateReward();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._textInput.dispose(param1);
            this._textInput = null;
            this._getRewardBtn.dispose(param1);
            this._getRewardBtn = null;
            this._rewardList.length = 0;
            super.disposeImpl(param1);
            return;
        }// end function

        private function getReward(event:MouseEvent) : void
        {
            if (this._textInput.text == "" || this._textInput.text == this._textInput.defaultText)
            {
                MsgManager.showMouseMsg(Language.getString(35106), MsgRollTipsType.msgRollTips2);
                return;
            }
            GameProxy.role.activeNewbieCode(this._textInput.text);
            return;
        }// end function

        private function updateReward() : void
        {
            var _loc_3:Array = null;
            var _loc_4:Array = null;
            var _loc_5:ItemData = null;
            var _loc_6:int = 0;
            var _loc_7:int = 0;
            var _loc_8:int = 0;
            var _loc_9:int = 0;
            var _loc_10:EffectItem = null;
            var _loc_1:* = RebateUtil.getEveryDayFirstGiftCode();
            var _loc_2:* = ItemConfig.instance.getConfig(120502003) as ItemGiftBagInfo;
            if (_loc_2)
            {
                _loc_3 = _loc_2.itemList1.split("&");
                _loc_6 = _loc_3.length;
                while (_loc_7 < _loc_6)
                {
                    
                    if (_loc_3[_loc_7])
                    {
                        _loc_4 = _loc_3[_loc_7].split("#");
                        _loc_5 = new ItemData(int(_loc_4[1]));
                        if (_loc_5.itemInfo && ItemsUtil.isFitCarrer(_loc_5))
                        {
                            _loc_10 = UICompomentPool.getUICompoment(EffectItem);
                            _loc_10.setItemStyle(ItemStyleConst.Big, ImagesConst.RewardItemBigBg, 4, 4);
                            _loc_10.isDragAble = false;
                            _loc_10.isDropAble = false;
                            _loc_10.isShowLock = true;
                            _loc_10.itemData = _loc_5;
                            _loc_10.amount = _loc_4[2];
                            _contentTopOf3DSprite.addChild(_loc_10);
                            this.pushUIToDisposeVec(_loc_10);
                            this._rewardList.push(_loc_10);
                        }
                    }
                    _loc_7++;
                }
                _loc_6 = this._rewardList.length;
                _loc_8 = 80;
                _loc_9 = (this.width - _loc_6 * 80) * 0.5 + 21;
                _loc_7 = 0;
                while (_loc_7 < _loc_6)
                {
                    
                    this._rewardList[_loc_7].x = _loc_9 + _loc_8 * _loc_7;
                    this._rewardList[_loc_7].y = 434;
                    this._rewardList[_loc_7].showEffect(true, 36, 32, "ArriundEffect_cheng_big.swf");
                    _loc_7++;
                }
            }
            return;
        }// end function

        public static function get instance() : WechatRewardModule
        {
            if (_instance == null)
            {
                _instance = new WechatRewardModule;
            }
            return _instance;
        }// end function

        public static function get isViewShow() : Boolean
        {
            return _instance && !_instance.isHide;
        }// end function

    }
}
